//
//  UIImage+Clips.m
//  LittleFairyPoet
//
//  Created by rimi on 15/9/21.
//  Copyright © 2015年 周林. All rights reserved.
//

#import "UIImage+Clips.h"

@implementation UIImage (Clips)

+ (UIImage*) imageWithImage:(UIImage*) image radius :(CGFloat) radius {
    
    UIGraphicsBeginImageContext(CGSizeMake(radius, radius));
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    //圆的边框宽度为2，颜色为红色
    
    CGContextSetLineWidth(context,2);
    
    CGContextSetStrokeColorWithColor(context, [UIColor clearColor].CGColor);
    
    CGRect rect = CGRectMake(0, 0, radius, radius);
    
    CGContextAddEllipseInRect(context, rect);
    
    CGContextClip(context);
    
    //在圆区域内画出image原图
    
    [image drawInRect:rect];
    
    CGContextAddEllipseInRect(context, rect);
    
    CGContextStrokePath(context);
    
    //生成新的image
    
    UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return newimg;
    
}
@end
